public class MissingTwo {
    public int[] missingTwo(int[] nums) {
        int ret = 0;
        // 相当于把两组元素合起来
        for (int x : nums) {
            ret ^= x;
        }
        for (int i = 1; i <= nums.length + 2; i++) {
            ret ^= i;
        }

        // 拿到两个数字异或后最低位 1
        int flag = (ret == Integer.MIN_VALUE ? Integer.MIN_VALUE : ret & -ret);
        int[] answer = new int[2];
        for (int i = 1; i <= nums.length +2; i++) {
            // 分成两类, 一类是标志bit位为0的, 一类是标志bit位为1的
            if((i & flag) == 0) {
                answer[0] ^= i;
            }else {
                answer[1] ^= i;
            }
        }

        for(int x : nums) {
            if((x & flag) == 0) {
                answer[0] ^= x;
            }else {
                answer[1] ^= x;
            }
        }
        return answer;
    }
}
